import numpy as np

# A是array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15])
A = np.arange(16)
print(A)

# 将A变换为三维矩阵
A = A.reshape(2,2,4)
print(A)

B=A.transpose((0,1,2))  #保持A不变
print(B)
C=A.transpose((0,2,1))  #将 0轴 和 1轴 交换
print(C)

import torch

x = torch.ones(2, 2, requires_grad=True)
y = x*8
z = y.transpose(0,1)
z=z*2
out =z[0][0]
# 求梯度 backward()
out.backward()
# 查看梯度
print(x.grad)
